//----------------------------------
//----------Bug Spawner SWEEEP------
//-----Made by Brian Nevec----------
//----------------------------------
//---Part of the SMOD Weapons Pack--
//----------------------------------

//if on server
if SERVER then

	//add the file
	AddCSLuaFile("shared.lua");

	//set the hold type
	SWEP.HoldType			= "melee";

end

//if on client
if CLIENT then

	//set some stuff
	SWEP.PrintName			= "Bug Spawner";
	SWEP.Author				= "Brian Nevec";
	SWEP.Slot				= 4;
	SWEP.SlotPos			= 3;
	SWEP.Purpose			= "Spawn friendly antlions";
	SWEP.Instructions		= "Left Click: Throw a normal antlion spawner, Right Click: Throw a guard spawner";

	//set the category
	SWEP.Category			= "SMOD";
	
	//selection icon
	SWEP.WepSelectIcon = surface.GetTextureID("weapons/smodbugicon");

end

//is it spawnable?
SWEP.Spawnable				= true;
SWEP.AdminSpawnable			= false;

//models
SWEP.ViewModel				= "models/weapons/v_bugspawner.mdl";
SWEP.WorldModel				= "models/weapons/w_bugspawner.mdl";

//more stuff
SWEP.Weight					= 25;
SWEP.AutoSwitchTo			= false;
SWEP.AutoSwitchFrom			= false;

//primary settings
SWEP.Primary =
{
	ClipSize				= -1,
	DefaultClip				= -1,
	Automatic				= true,
	Ammo					= "none"
}

//secondary settings
SWEP.Secondary =
{
	ClipSize				= -1,
	DefaultClip				= -1,
	Automatic				= true,
	Ammo					= "none"
}

SWEP.Sounds =
{
}

//on initialize
function SWEP:Initialize()

	//if on server
	if SERVER then

		//set the hold type
		self:SetWeaponHoldType(self.HoldType);

	end

end

//when we want to attack with the primary
function SWEP:PrimaryAttack()

	if SERVER then
	
		local Ent = ents.Create("smod_thrownbug");
	
		if ValidEntity(Ent) then
		
			Ent:SetPos(self.Owner:GetShootPos());
			Ent:SetAngles(self.Owner:GetAimVector():Angle());
			Ent:SetOwner(self.Owner);
			Ent:SetBigBug(false);
			
			Ent:Spawn();
			Ent:Activate();
			
			local Physics = Ent:GetPhysicsObject();
			
			if ValidEntity(Physics) then
			
				Physics:ApplyForceCenter(self.Owner:GetAimVector() * 6000);
				
				local function C()

					if ValidEntity(self.Weapon) then

						self.Weapon:SendWeaponAnim(ACT_VM_DRAW);

					end

				end
				timer.Simple(0.2,C);
				
			else
			
				Ent:Remove();
			
			end
		
		end
	
	end
	
	self.Weapon:SendWeaponAnim(ACT_VM_THROW);
	
	//delay the fire
	self.Weapon:SetNextSecondaryFire(CurTime() + 0.7);
	self.Weapon:SetNextPrimaryFire(CurTime() + 0.6);

	//return false
	return false;

end

function SWEP:SecondaryAttack()

	if SERVER then
	
		local Ent = ents.Create("smod_thrownbug");
	
		if ValidEntity(Ent) then
		
			Ent:SetPos(self.Owner:GetShootPos());
			Ent:SetAngles(self.Owner:GetAimVector():Angle());
			Ent:SetOwner(self.Owner);
			Ent:SetBigBug(true);
			
			Ent:Spawn();
			Ent:Activate();
			
			local Physics = Ent:GetPhysicsObject();
			
			if ValidEntity(Physics) then
			
				Physics:ApplyForceCenter(self.Owner:GetAimVector() * 5000);
				
				local function C()

					if ValidEntity(self.Weapon) then
					
						self.Weapon:SendWeaponAnim(ACT_VM_DRAW);
					
					end
			
				end
				timer.Simple(0.2,C);

				
			else
			
				Ent:Remove();
			
			end
		
		end
	
	end
	
	self.Weapon:SendWeaponAnim(ACT_VM_THROW);
	
	//delay the fire
	self.Weapon:SetNextSecondaryFire(CurTime() + 0.7);
	self.Weapon:SetNextPrimaryFire(CurTime() + 0.6);

	//return false
	return false;

end

//when we deploy
function SWEP:Deploy()

	//run the deploy animation
	self.Weapon:SendWeaponAnim(ACT_VM_DRAW);

	//and return
	return true;

end